package util.validate
{
	import MyApp.Model.Business.Member;
	import MyApp.View.ValueEvent;
	
	import com.adobe.utils.StringUtil;
	
	import mx.collections.ArrayCollection;
	import mx.validators.ValidationResult;
	import mx.validators.Validator;
	
	import nz.co.codec.flexorm.EntityManager;
	import nz.co.codec.flexorm.criteria.Criteria;
	
	import util.GDUtil;
	
	public class MemberCardUniqueValidate extends Validator
	{	
		public static const IS_BEING_DATA:String = GDUtil.getUID();
		private var _userError:String;
		
		private var _member:Member;
		
		private var _isBeingValue:Boolean;
		public function MemberCardUniqueValidate()
		{
			super();
		}
		
		public function get isBeingValue():Boolean
		{
			return _isBeingValue;
		}

		public function set isBeingValue(value:Boolean):void
		{
			_isBeingValue = value;
		}

		public function get member():Member
		{
			return _member;
		}

		public function set member(value:Member):void
		{
			_member = value;
		}
		public function set userError(value:String):void{
			this._userError=value;
		}
		public function get userError():String{
			return this._userError;
		}
		
		override protected function doValidation(value:Object):Array{
			var results:Array= new Array();
			var cardNO:String =StringUtil.trim(String(value));
			//数据库验证
			var em:EntityManager=EntityManager.getInstance();
			var cri:Criteria=em.createCriteria(Member);
			cri.addEqualsCondition("member_no",cardNO);
			var data:ArrayCollection=em.fetchCriteria(cri);
			if(data.length==1){
				results.push(new ValidationResult(true,"","userError",userError));
				member=data.getItemAt(0) as Member;
			}
			return results;
		}
	}
	
	
	
}